package com.cloud.sample.index;

import com.cloud.common.elasticsearch.ElasticsearchSupport;
import com.cloud.common.util.DateTimeUtils;
import com.fasterxml.jackson.annotation.JsonAlias;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.DateFormat;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

import java.util.Date;

@Data
@Document(indexName = "sample-product", shards = 3)
public class IndexProduct {
    @Id
    @Field(type = FieldType.Long)
    private Long id;

    @Field(type = FieldType.Text)
    private String name;

    @Field(type = FieldType.Keyword)
    private String type;

    @Field(type = FieldType.Text, analyzer = ElasticsearchSupport.ANALYZER_WHITESPACE)
    private String label;

    @Field(type = FieldType.Keyword)
    private String color;

    @Field(type = FieldType.Integer)
    private Integer amount;

    @Field(type = FieldType.Integer)
    private Integer price;

    @Field(type = FieldType.Text, index = false)
    private String description;

    @Field(type = FieldType.Date_Range, format = DateFormat.custom, pattern = DateTimeUtils.DATE_TIME_FORMAT)
    @JsonFormat(pattern = DateTimeUtils.DATE_TIME_FORMAT)
    @JsonAlias("release_time")
    private Date releaseTime;


    public static final String ID = "id";
    public static final String NAME = "name";
    public static final String TYPE = "type";
    public static final String LABEL = "label";
    public static final String COLOR = "color";
    public static final String AMOUNT = "amount";
    public static final String PRICE = "price";
    public static final String DESCRIPTION = "description";
    public static final String RELEASETIME = "releaseTime";
}
